<!DOCTYPE HTML>
<html>

<head>
  <meta charset="utf-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <title>生意云</title>
  <meta name="description" content="生意云" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <script>
    function getUrlParam (name, url) {
      var reg = new RegExp(`(^|&)${name}=([^&]*)(&|$)`);
      var curStr = url ? url.split('?') : window.location.href.split('?');
      var r = '';
      if (curStr[1]) {
        r = curStr[1].match(reg); // search,查询？后面的参数，并匹配正则
        if (r !== null) return unescape(r[2]);
      }
      return r;
    }

    function fetchData(callback) {
      var xmlhttp;
      if (window.XMLHttpRequest) {
        //  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
        xmlhttp=new XMLHttpRequest();
      }
      else {
        // IE6, IE5 浏览器执行代码
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
      xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState === 4 && xmlhttp.status === 200){
          callback && callback(xmlhttp.responseText)
        }
      }
      var env = getUrlParam('env') || '';
      var turId = getUrlParam('turId') || '';
      var url = 'https://www.boc2022.com';
      if(env === 'test') {
        url = 'https://www.redgang.cn';
      }
      xmlhttp.open("GET", `${url}/core/order/common/miniAppRoute?turId=${turId}`, true);
      xmlhttp.send();
    }
  </script>
  <style>
    .main-box {
      position: relative;
      margin-top: 128px;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      font-weight: 500;
      font-size: 20px;
      line-height: 28px;
      color: #000000;
      visibility: hidden;
    }

    .info-text {
      position: absolute;
      bottom: 26px;
      width: 100%;
      text-align: center;
    }
  </style>

</head>

<body>
  <div class="main-box" id="mainBox">
    <img src="https://public-1256988483.cos.ap-guangzhou.myqcloud.com/web-scan.png" width="215px" height="285px">
    <div class="info-text">请使用微信或支付宝扫码</div>
  </div>
  <script>
    (function() {
      var curEnv = '';
      var ua = window.navigator.userAgent;
      //判断是不是微信
      if (ua.indexOf("MicroMessenger") >= 0) {
        curEnv= "WeiXIN";
      }
      //判断是不是支付宝
      if(ua.indexOf("Alipayclient") >= 0) {
        curEnv = "Alipay";
      }

      if(!curEnv) {
        console.log('userAgent==', ua);
        document.querySelector('#mainBox').style.visibility = 'visible';
      } else {
        fetchData(function(res) {
          var resData = res && JSON.parse(res)
          if(resData && resData.code === 0) {
            location.replace(`https://www.redgang.cn/miniApp/route/${resData.data}`);
          } else {
            console.log(res)
          }
        });
      }
    })()
  </script>
</body>
</html>
</DOCTYPE>
